<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="container">
    <input type="text" name="" id="username" placeholder="请输入用户名"><br />
    <input type="password" name="" id="password" placeholder="请输入密码"><br />
    <button id="btn">注册</button><button id="login">去往登录</button>
  </div>
  <script>
    const username = document.querySelector('#username')
    const password = document.querySelector('#password')
    const btn = document.querySelector('#btn')
    const login = document.querySelector('#login');
    btn.onclick = function() {
      const name = username.value;
      const pass = password.value
      console.log('9sdsd', {
        name,
        pass
      })
      fetch('http://localhost:7001/user/register', {
        method: 'post',
        headers: {
          'Content-Type': 'application/json; charset=utf-8'
        },
        body: JSON.stringify({
          username: name,
          password: pass
        })
      }).then(()=> {
        getUserInfo()
      })
    }
    function getUserInfo () {
      return fetch('http://localhost:7001/user/getUserInfo', {
          method: 'get'
        }).then(res => {
          console.log('res', res)
        })
    }
    login.onclick = function() {
      location.href = './login/html'
    }
</script>
</body>
</html>